package com.ybwh.springboot2.conf;

import com.ybwh.springboot2.common.mail.EmailSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * <p>
 * 邮件配置
 * </p>
 *
 * @author fanbeibei
 * @version V1.0
 * @since 2019/9/10 12:51
 */
@Configuration
@ConditionalOnProperty(prefix = "spring.mail", name = "host")
public class EmailSenderConfig {

    @Bean
    public EmailSender emailSender(@Autowired JavaMailSender javaMailSender,
                                   @Value("${spring.mail.from}") String from,
                                   @Value("${spring.mail.to}") String to) {
        return new EmailSender(javaMailSender, from, to);
    }


}
